<template>
  <div class="comment-post">
    <van-field
      class="post-field"
      v-model.trim="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="50"
      placeholder="请输入留言"
      show-word-limit
    />
    <van-button
      @click="sendComment"
      class="post-btn"
      :disabled="!message.length"
      >发布</van-button
    >
  </div>
</template>

<script>
import { commentsPost } from '@/api/articles'
export default {
  props: ['target'],

  data() {
    return {
      message: '',
    }
  },

  methods: {

    // 发布文章评论请求
    async sendComment() {
      if (this.$store.state.userToken) {
        const { data: res } = await commentsPost({
          target: this.target,
          content: this.message,
          art_id:null
        })
        console.log(res,2222)
        this.$emit('commentVlue' , res.data.new_obj) 
      } else {
        this.$toast.fail('未登录， 请先登录！！！')
      }
    },
  },
}
</script>

<style scoped lang="less">
.comment-post {
  display: flex;
  align-items: center;
  padding: 32px 0 32px 32px;
  .post-field {
    background-color: #f5f7f9;
  }
  .post-btn {
    width: 150px;
    border: none;
    padding: 0;
    color: #6ba3d8;
    &::before {
      display: none;
    }
  }
}
</style>